﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Mammoth.Entities;
using Mammoth.Events;
using Mammoth.Libs;
using Mammoth.Services;

namespace Mammoth.ViewModels
{
    public static class EventItemEventRaiser
    {
        public static void RaiseErrorEvent(this IInputElement vm, string message)
        {
            ThreadSaveRaiseEvent(vm, new EventItemEventArgs(new ErrorEventItemEntity(message)));
        }

        public static void RaiseInboxEvent(this IInputElement vm, string serviceEmail, string buddyEmail, string msg)
        {
            ThreadSaveRaiseEvent(vm, new EventItemEventArgs(new InboxEventItemEntity(serviceEmail, buddyEmail, msg)));
        }

        public static void RaiseOutboxEvent(this IInputElement vm, string serviceEmail, string buddyEmail, string msg)
        {
            ThreadSaveRaiseEvent(vm, new EventItemEventArgs(new OutboxEventEntity(serviceEmail, buddyEmail, msg)));
        }

        public static void RaiseSubscriptionEvent(this IInputElement vm, string serviceEmail, string buddyEmail)
        {
            ThreadSaveRaiseEvent(vm, new EventItemEventArgs(new SubscriptionEventItemEntity(serviceEmail, buddyEmail)));
        }

        public static void RaiseNavigationEvent(this IInputElement vm, NavigationType type = NavigationType.Backward, Type view = null, IParameterValue arguments = null)
        {
            ThreadSaveRaiseEvent(vm, new ViewNavigationEventArgs(type, view, arguments));
        }

        public static void RaiseMessageDataChangeEvent(this IInputElement vm)
        {
            ThreadSaveRaiseEvent(vm, new MessageDataChangeEventArgs());
        }

        private static void ThreadSaveRaiseEvent(IInputElement vm, RoutedEventArgs e)
        {
            Application.Current.Dispatcher.Invoke(() => vm.RaiseEvent(e));
        }

    }
}
